export let base='http://localhost:3000'
/*
注册  
*/
export let userRegister=async (userName,upwd,avatar,perSign)=>{
	let url=base+'/user/register'
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url,
		method:'POST',
		data:{userName,upwd,avatar,perSign},
		header:{'Content-Type':'application/x-www-form-urlencoded'}
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'网络请求失败'}
	}else{
		return res.data
	}
};

/*
登录
*/
export let userLogin=async (userName,upwd)=>{
	let url=base+`/user/login`
	uni.showLoading({
		title:'正在登录中'
	})
	let [err,res]=await uni.request({
		url,
		method:'POST',
		data:{userName,upwd},
		header:{'Content-Type':'application/x-www-form-urlencoded'}
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'网络请求失败'}
	}else{
		return res.data
	}
}

/*
查询所有用户
*/
export let queryAllUsers=async ()=>{
	let url=base+'/user/queryAll'
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'request fail'}
	}else{
		return res.data
	}
}

/*
模糊搜索用户
*/
export let queryUser=async (userName)=>{
	let url=base+`/user/queryLike?userName=${userName}`
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'request fail'}
	}else{
		return res.data
	}
}
/*
增加好友
*/
export let addfriend1=async (aname,apic,aSign)=>{
	let url=base+'/addfriend/add'
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url,
		method:'POST',
		data:{aname,apic,aSign},
		header:{'Content-Type':'application/x-www-form-urlencoded'}
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'网络请求失败'}
	}else{
		return res.data
	}
};

/*
展示所有好友
*/
export let queryAllFriends=async ()=>{
	let url=base+'/addfriend/queryAll'
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'request fail'}
	}else{
		return res.data
	}
}

// 删除好友
export let delFriends=async (aid)=>{
	let url=base+`/addfriend/delete?aid=${aid}`
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'request fail'}
	}else{
		return res.data
	}
}

/*
模糊搜索好友
*/
export let queryFriendsByNameLike=async (aname)=>{
	let url=base+`/addfriend/queryLike?aname=${aname}`
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'request fail'}
	}else{
		return res.data
	}
}

// 修改好友备注
export let modifyFriend=async (aid,aname)=>{
	let url=base+'/addfriend/modify'
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url,
		method:'POST',
		data:{aid,aname},
		header:{'Content-Type':'application/x-www-form-urlencoded'}
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'网络请求失败'}
	}else{
		return res.data
	}
};

// 通过姓名查找用户信息
export let queryByName=async (userName)=>{
	let url=base+`/user/queryByName?userName=${userName}`
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'request fail'}
	}else{
		return res.data
	}
}

//发朋友圈
export let sendfriend=async (userName,title,avatar,contentPic)=>{
	let url=base+'/friend/add'
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url,
		method:'POST',
		data:{userName,title,avatar,contentPic},
		header:{'Content-Type':'application/x-www-form-urlencoded'}
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'网络请求失败'}
	}else{
		return res.data
	}
};

// 加载朋友圈列表
export let queryQuan=async ()=>{
	let url=base+'/friend/queryAll'
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'request fail'}
	}else{
		return res.data
	}
}

// 删除朋友圈
export let delQuan=async (friendId)=>{
	let url=base+`/friend/delete?friendId=${friendId}`
	uni.showLoading({
		title:'正在加载中'
	})
	let [err,res]=await uni.request({
		url
	})
	uni.hideLoading()
	if(err){
		return {code:500,msg:'request fail'}
	}else{
		return res.data
	}
}
